home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgramD2.iso
/
Borland
/
Borland C++ V5.02
/
SCRPTEXM.PAK
/
SORT.SPP
< prev
next >
Wrap
Text File
|
1997-05-06
|
754b
|
33 lines
//--------------------------------------------------------------------------
// Object Scripting
// Copyright (c) 1996 by Borland International, All Rights Reserved
//
// SORT.SPP: Sort. Quick Sort routines.
//--------------------------------------------------------------------------
QuickSort(v, left, right)
{
declare last;
if (left >= right) {
return;
}
QuickSortSwap(v, left, (left + right) / 2);
last = left;
for (declare i = left + 1; i <= right; i++) {
if (v[i] < v[left]) QuickSortSwap(v, ++last, i);
}
QuickSortSwap(v, left, last);
QuickSort(v, left, last - 1);
QuickSort(v, last + 1, right);
}
QuickSortSwap(v, i, j)
{
declare tmp;
tmp = v[i];
v[i] = v[j];
v[j] = tmp;
}